import mongoose, { Schema } from 'mongoose';

const schema = new Schema(
  {
    name: String,
    isCustomer: Boolean,
    members: [{ type: Schema.Types.ObjectId, ref: 'User' }],
    responseGroups: [{ type: Schema.Types.ObjectId, ref: 'Group' }],
  },
  {
    collection: 'groups',
  },
);

schema.methods.isTeacherGroup = function isTeacherGroup() {
  return this.name === '老师';
};

schema.methods.getRedisGroupName = function getRedisGroupName() {
  return `group:${this.id}`;
};

export default mongoose.model('Group', schema);
